package com.res.simulator.transformer;

import java.util.ArrayList;
import java.util.List;
import com.res.common.transformer.BaseTransformer;
import com.res.simulator.model.SelectTemplateModel;
import com.res.simulator.view.ConsumerTemplateSearchResultsView;
import com.sip.dbadapter.dao.domain.ConsumeTemplate;
import com.sip.dbadapter.dao.domain.ScanTypeRest;
import com.sip.dbadapter.dao.domain.ScanTypeRmi;
import com.sip.dbadapter.dao.domain.ScanTypeWs;

public class ConsumeTemplateSearchTransformer implements
    BaseTransformer<SelectTemplateModel, List<ConsumerTemplateSearchResultsView>, List<ConsumeTemplate>> {

    public List<ConsumeTemplate> transformModelToDomian(SelectTemplateModel model) throws Exception {

        // TODO Auto-generated method stub
        List<ConsumeTemplate> consumeTemplateList = new ArrayList<ConsumeTemplate>();
        ConsumeTemplate consumeTemplate = new ConsumeTemplate();

        if (model.getTemplateId() != null)
            consumeTemplate.setTemplateId(model.getTemplateId());
        ScanTypeWs scanWs = new ScanTypeWs();
        ScanTypeRmi scanRmi = new ScanTypeRmi();
        ScanTypeRest scanRest = new ScanTypeRest();
        if (model.getApiId() != null)
            scanWs.scanTypeId = Long.parseLong(model.getApiId());

        consumeTemplate.setScanTypeWs(scanWs);
        consumeTemplate.setScanTypeRmi(scanRmi);
        consumeTemplate.setScanTypeRest(scanRest);
        consumeTemplateList.add(consumeTemplate);

        return consumeTemplateList;
    }

    public List<ConsumerTemplateSearchResultsView> transformDomianToView(List<ConsumeTemplate> consumeTemplateList) throws Exception {

        // TODO Auto-generated method stub
        List<ConsumerTemplateSearchResultsView> templateSearchResultViewList = new ArrayList<ConsumerTemplateSearchResultsView>();

        for (ConsumeTemplate consumeTemplate : consumeTemplateList) {
            ConsumerTemplateSearchResultsView searchView = new ConsumerTemplateSearchResultsView();
            searchView.setTemplateId(consumeTemplate.getTemplateId());
            searchView.setContent(consumeTemplate.getContent());
            searchView.setSaveDate(consumeTemplate.getSavedDate());
            searchView.setApiName(consumeTemplate.getApiName());
            templateSearchResultViewList.add(searchView);
        }
        // this is temporarily hard coded.
        return templateSearchResultViewList;
    }

}
